package com.bt.lms.dao.servise.impl;

import com.bt.lms.dao.servise.TransferInfoDao;
import com.bt.lms.entity.TransferInfo;
import com.bt.lms.utils.DriverUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 学籍异动信息dao
 * @author 王波
 *
 */
public class TransferInfoDaoImpl implements TransferInfoDao {


    @Override
    public int insert(String sql, TransferInfo transferInfo) throws SQLException {
        //异动类别
        Integer transferType = transferInfo.getType();
        //异动前学籍状态
        Integer beforeState = transferInfo.getBeforeState();
        //异动原因
        String transferCause = transferInfo.getCause();
        //异动后学籍状态
        Integer laterState = transferInfo.getLaterState();
        //异动日期
        Date transferDate = transferInfo.getDate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = simpleDateFormat.format(transferDate);
        //异动说明
        String explain = transferInfo.getExplain();
        Long stuStatusInfoID = transferInfo.getStuStatusInfoID();

        Connection conn = DriverUtils.Driver();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setInt(1,transferType);
        ps.setInt(2,beforeState);
        ps.setString(3,transferCause);
        ps.setInt(4,laterState);
        ps.setString(5, date);
        ps.setString(6,explain);
        ps.setLong(7,stuStatusInfoID);


        int i = ps.executeUpdate();

        //关闭资源
        ps.close();
        conn.close();
        return i;
    }

    @Override
    public boolean update(String sql, TransferInfo transferInfo,Long id) throws SQLException {
        //异动类别
        Integer transferType = transferInfo.getType();
        //异动前学籍状态
        Integer beforeState = transferInfo.getBeforeState();
        //异动原因
        String transferCause = transferInfo.getCause();
        //异动后学籍状态
        Integer laterState = transferInfo.getLaterState();
        //异动日期
        Date transferDate = transferInfo.getDate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = simpleDateFormat.format(transferDate);
        //异动说明
        String explain = transferInfo.getExplain();

        Connection conn = DriverUtils.Driver();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setInt(1,transferType);
        ps.setInt(2,beforeState);
        ps.setString(3,transferCause);
        ps.setInt(4,laterState);
        ps.setString(5, date);
        ps.setString(6,explain);
        ps.setLong(7,id);

        int i = ps.executeUpdate();


        //关闭资源
        ps.close();
        conn.close();
        return false;
    }


}
